<?php
declare(strict_types=1);
namespace App\System\Controller;

use Haozing\FastCore\Abstract\AbstractController;
use Haozing\FastCore\Constants\ErrorCode;
use Haozing\FastCore\Exception\CommonException;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use App\System\Logic\HeiRoleLogic;

#[Controller]
class HeiRoleController extends AbstractController
{
    #[Inject]
    protected HeiRoleLogic $heiRoleLogic;

    /**
     * 新增
     * @return array
     */
    #[RequestMapping(path: '/system/heiRole/add',methods: 'post')]
    public function add(): array
    {
        // 验证参数
        $params = $this->request->all();
        $validator = $this->validationFactory->make($params,
            [
                'name' => 'required',
                'code' => 'required',
                'data_scope' => 'required',
                'status' => 'required',
                'sort' => 'required',
                'created_by' => 'required',
                'updated_by' => 'required',
                'tenant_id' => 'required',
                'created_at' => 'required',
                'remark' => 'required',

            ],
            [
                'name.required' => '角色名称不能为空',
                'code.required' => '角色代码不能为空',
                'data_scope.required' => '数据范围（1：全部数据权限 2：自定义数据权限 3：本部门数据权限 4：本部门及以下数据权限 5：本人数据权限）不能为空',
                'status.required' => '状态 (1正常 2停用)不能为空',
                'sort.required' => '排序不能为空',
                'created_by.required' => '创建者不能为空',
                'updated_by.required' => '更新者不能为空',
                'tenant_id.required' => '租户ID不能为空',
                'created_at.required' => '创建时间不能为空',
                'remark.required' => '备注不能为空',

            ]
        );

        if ($validator->fails()){
            throw new CommonException(ErrorCode::INVALID_PARAM,$validator->errors()->first());
        }
        // 执行业务逻辑
        $data = $this->heiRoleLogic->add($params);

        return $data;
    }
    /**
     * 删除
     * @return array
     */
    #[RequestMapping(path: '/system/heiRole/delete',methods: 'post')]
    public function delete(): array
    {
        // 验证参数
        $params = $this->request->all();
        $validator = $this->validationFactory->make($params,
            [
                'id' =>'required',
            ],
            [
                'id.required' => 'id不能为空',
            ]
        );

        if ($validator->fails()){
            throw new CommonException(ErrorCode::INVALID_PARAM,$validator->errors()->first());
        }
        // 执行业务逻辑
        $data = $this->heiRoleLogic->delete($params);

        return $data;
    }

    /**
     * 更新
     * @return array
     */
    #[RequestMapping(path: '/system/heiRole/update',methods: 'post')]
    public function update(): array
    {
        // 验证参数
        $params = $this->request->all();
        $validator = $this->validationFactory->make($params,
            [
                'id' =>'required',
            ],
            [
                'id.required' => 'id不能为空',
            ]
        );

        if ($validator->fails()){
            throw new CommonException(ErrorCode::INVALID_PARAM,$validator->errors()->first());
        }
        // 执行业务逻辑
        $data = $this->heiRoleLogic->update($params);

        return [];
    }

    /**
     * 列表查询
     * @return array
     */
    #[RequestMapping(path: '/system/heiRole/list',methods: 'post')]
    public function list(): array
    {
        // 验证参数
        $params = $this->request->all();
        // 执行业务逻辑
        $data = $this->heiRoleLogic->list($params);
        return $data;

    }
    /**
     * 列表查询select
     * @return array
     */
    #[RequestMapping(path: '/system/heiRole/select',methods: 'post')]
    public function select(): array
    {
        // 验证参数
        $params = $this->request->all();
        // 执行业务逻辑
        $data = $this->heiRoleLogic->select($params);
        return $data;

    }
    /**
     * 详情
     * @return array
     */
    #[RequestMapping(path: '/system/heiRole/detail',methods: 'get')]
    public function detail(): array
    {
        //验证参数
        $params = $this->request->all();
        $validator = $this->validationFactory->make($params,
            [
                'id' =>'required',
            ],
            [
                'id.required' => 'id不能为空',
            ]
        );

        if ($validator->fails()){
            throw new CommonException(ErrorCode::INVALID_PARAM,$validator->errors()->first());
        }
        // 执行业务逻辑
        $data = $this->heiRoleLogic->detail($params);
        return $data;
    }

}